<template>
    <div>
        <el-dialog title="互见号" :visible.sync="open" width="50%" append-to-body :before-close="closeDelDialog">
            <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
                <el-form-item label="档号" prop="dh">
                    <el-input v-model="queryParams.dh" placeholder="档号查询" clearable style="width: 240px"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>


                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8" ref="refbut">
                <el-col :span="1.5">
                    <el-button type="primary" @click="addTap">新增互见</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button @click="hjgxQuery">查看互见关系</el-button>
                </el-col>
            </el-row>
            <el-table v-loading="loading" :data="daListData" @selection-change="handleSelectionChange" border height="500px"
                @cell-dblclick="celldblclick">
                <el-table-column type="selection" width="50" align="center" />
                <el-table-column label="序号" type="index" />
                <el-table-column label="档案标题" align="center" prop="TITLE" :show-overflow-tooltip="true" />
                <el-table-column label="档号" align="center" prop="DH" :show-overflow-tooltip="true" />
                <el-table-column label="年度" align="center" prop="ND" :show-overflow-tooltip="true" />
                <el-table-column label="保管期限" align="center" prop="BGQX" width="120">
                    <template slot-scope="scope">
                        <span v-for="(i, idx) in dict.type.BGQX" :key="idx">
                            {{ scope.row.BGQX == i.value ? i.label : '' }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="全宗号" align="center" prop="QZH" width="120">

                </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getdaList" />
        </el-dialog>
        <queryList v-if="queryOpen" :queryOpen="queryOpen" @closeDelDialog="closeDelDialogLIST" :daId="daId" :menuId="menuId"></queryList>
        <!--start  组件详情 -->
        <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbDatajh"
            @detailsHandleClose="detailsHandleClose">
        </jianDetailsOpen>
        <!--end 组件详情 -->
        <!-- start 组卷\项目详情 -->
        <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbDatajh"
            @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
        <!-- end 组卷\项目详情 -->
    </div>
</template>
<script>
import {daList, associationPOST,getRole} from "@/api/archive/filesManage/filesManageMenu.js" //档案管理
import queryList from "@/views/archive/filesManage/filesManageMenu/hjhao/queryList.vue"
import { getLastIndexOf } from "@/utils/index.js"
import { getthbytreenodeHeaderList } from "@/api/archive/fileCollection/offlinReception.js";
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情'
export default {
    components: {
        queryList, jianDetailsOpen, juanDetailsOpen
    },
    // <!--start 互见号  type==1 '档案整理'  type==2 '（目录检索，全文检索）' 判断是否可打卡详情--> 
    props: ['open', 'daId', 'menuId','hjhaoType'],
    archive_Dicts: ['BGQX'],
    data() {
        return {
            queryOpen: false,
            loading: false,
            daListData: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                dh: undefined
            },
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            jianDetailsOpen:false,
            juanDetailsOpen:false,
            celldbDatajh: undefined
        }
    },
    created(){
        this.getdaList();
    },
    methods: {
        closeDelDialog() {
            this.$emit("closeDelDialog")
        },
        closeDelDialogLIST() {
            this.queryOpen = false
        },
        handleQuery() {
            this.loading = true;
            this.getdaList();
        },

        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.DAID);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        //查詢列表
        getdaList() {
            daList(this.queryParams).then(res => {
                this.daListData = res.rows;
                this.total = res.total;
                this.loading = false;
            })
        },
        //添加互关
        addTap() {
            if (!this.multiple) {
                associationPOST({
                    daId: this.daId,
                    glIds: this.ids,
                    "type": "0"
                }).then(res => {
                    if (res.code == 200) {
                        this.$modal.msgSuccess("互关成功")
                    }
                })
            } else {
                this.$message({ message: '请选择档案哦', type: 'warning' })
            }
        },

        //查看互见关系
        hjgxQuery() {
            this.queryOpen = true
        },

        //双击列表进入详情页面
        celldblclick(row) {
            var level = "";
            var label = "";
            getRole({
                categoryId: row.CATEGORYID,
                menuId: this.menuId,
            }).then(res=>{
                //返回数据  true 可看详情，false 不能查看详情
                if(res.data){
                    getthbytreenodeHeaderList({
                categoryId: row.CATEGORYID,
                menuId: this.menuId,
                subTableName: row.SUB_TABLE_NAME
            }
            ).then(response => {
                var tableHeaderList = response.rows;


                if (getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 件
                    level = 0
                    label = row.TITLE;
                } else if (getLastIndexOf(row.SUB_TABLE_NAME) == "V") { //卷
                    level = 1
                    label = row.TITLE;
                } else { //项目
                    level = 3
                    label = row.XMMC;

                }
                this.celldbDatajh = {
                    id: row.DAID,
                    categoryId: row.CATEGORYID,
                    menuId: this.menuId,
                    sub_table_name: row.SUB_TABLE_NAME,
                    label: label,
                    level: level,
                    ifSub_table_name: row.SUB_TABLE_NAME,
                    isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                    tableHeaderList: tableHeaderList,
                    hjhao:this.type
                }
                this.$nextTick(() => {
                    if (getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 进入件详情
                        this.jianDetailsOpen = true;
                    } else { //进入卷详情 和项目详情
                        this.juanDetailsOpen = true
                    }
                })




            })
                }else{
                    this.$message({ message: '该用户没有权限查看详情哦！', type: 'warning' })
                }
                
            })
        },
        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.juanDetailsOpen = false;
        },
    }
}
</script>
<style lang="scss" scoped></style>